package com.sun.rabbitMQ.WorkQueues;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.sun.rabbitMQ.utils.FactoryUtils;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class ProducerACK {
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = FactoryUtils.getChannel();
        //队列持久化
        boolean durable = true;
        channel.queueDeclare(FactoryUtils.TASK_QUEUE_NAME,durable,false,false,null);
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
            //MessageProperties.PERSISTENT_TEXT_PLAIN 消息持久化
            channel.basicPublish("",FactoryUtils.TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes("utf-8"));
            System.out.println("发出消息了");
        }
    }
}
